package com.a918.controller;

import com.a918.entity.Score;
import com.a918.service.EvaluateService;
import com.a918.service.UserService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
public class EvaluateController {
    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(UserController.class);

    private UserService userService;
    private EvaluateService evaluateService;

    @Autowired
    public EvaluateController(UserService userService,EvaluateService evaluateService) {
        this.userService = userService;
        this.evaluateService=evaluateService;
    }

    @GetMapping("/evaluate")
    public String evaluate(Model model, HttpServletRequest request) {
        String type= request.getParameter("type");
        switch (type){
            case "ziyuanxiaolv":
                return "back/evaluateZiyuan";
            case "shengchanlv":
                return "back/evaluateShengchan";
            case "fuwujixiao":
                return "back/evaluateFuwu";
            case "zonghe":
                return "back/evaluate";
        }
        return "back/evaluate";
    }

    @PostMapping("/get_evaluate")
    @ResponseBody
    public Map<String,Object> get_evaluate(@RequestParam String wangdian, HttpServletRequest request) throws IOException {
        String type=request.getParameter("type");
        Map<String, Object> result=new HashMap<>();
        String yuefen;
        switch (type) {
            case "zong":
                yuefen = request.getParameter("yuefen");

                // TODO: 计算图数据 直接返回reusult（Map）即可
                String path = "/static/file/graph.json";
                JSONObject data;
                InputStream config = getClass().getResourceAsStream(path);
                if (config == null) {
                    throw new RuntimeException("读取文件失败");
                } else {
                    data  = JSON.parseObject(config, JSONObject.class);
                    // System.out.println(data);
                }

                return JSONObject.parseObject(data.toJSONString(), new TypeReference<Map<String, Object>>(){});
        }
        return result;
    }
}
